Skip to content

Runtime check and optional no_std#40

Open
lisicky wants to merge 4 commits intotyped-io:masterfrom
Emurgo:runtime_check
Open

Runtime check and optional no_std#40
lisicky wants to merge 4 commits intotyped-io:masterfrom
Emurgo:runtime_check

Conversation

@lisicky
Copy link
Copy Markdown
Contributor

@lisicky lisicky commented Jan 13, 2023

Despite that the previous PR #39 fixes compilation without x86 SIMDs flags, there is the case when a user of cryptoxide compiles for x86 and tries to execute code with cryptoxide can get an error SIGILL, because the code branch below works only in compile time.

By this PR I suggest adding a runtime SIMD support check and making cryptoxide std friendly because the is_x86_feature_detected is only available in the std. But I left the possibility to build cryptoxide as no_std by disabling default features. I can make an update for README.MD with instructions on how it can be done. That no_std manner I got from https://github.com/marshallpierce/rust-base64 and https://github.com/iqlusioninc/crates/tree/main/bip32 repos.

#[cfg(target_feature = "avx2")]
const HAS_AVX2: bool = true;
#[cfg(not(target_feature = "avx2"))]
const HAS_AVX2: bool = false;
if HAS_AVX2 {
return avx2::compress_b(&mut self.h, &mut self.t, buf, last);
}

@vincenthz
Copy link
Copy Markdown
Collaborator

in term of runtime check I think it's good, but not adding back std (or adding dependencies) is a stronger priority of mine for cryptoxide. Likely I imagine, adding a cpu.rs module with some inline assembly / cpuid checks. we need a very small subset of std::is_x86_feature_detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants